package array;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

//数组合并
public class Merge {
    public static void main(String[] args) throws Exception {
        String[] strArr = { "one", "two", "three" };
        String[] strArr2 = { "one1", "two", "three1" };

        //系统自带
        System.out.println("原生合并 "+ merge(strArr, strArr2));
       
        // 同类型数组合并
        ArrayList merge1 = new ArrayList(Arrays.asList(strArr));
        System.out.println(merge1.getClass().getTypeName());

        merge1.addAll(Arrays.asList(strArr2));
        System.out.println(merge1);

        // 不同类型数组合并  
        ArrayList list = new ArrayList<>();
        list.add("one");
        list.add(2);
        list.add("three");
        list.add(4);
        System.out.println("工具类："+ merge2(merge1,list)); //字符数组 和对象数组怎么转换???
   


        // 将相同元素覆盖操作 ???
        
        //填充元素
        int[] fillArr = new int[10];
        Arrays.fill(fillArr, 1);
        System.out.println(Arrays.toString(fillArr));


        String[] names = new String[] { "A", "B", "C" };
        String[] extended = new String[5];
        extended[3] = "D";
        extended[4] = "E";
        System.arraycopy(names, 0, extended, 0, names.length);
        for (String str : extended){
            System.out.println(str);
        }


    }

    

    public static ArrayList merge(String[] args,String[] args2){
        //系统自带
        int  len = args.length+args2.length;
        String[] strMerge = new String[len];
        System.arraycopy(args, 0, strMerge, 0, args.length);
        System.arraycopy(args2, 0, strMerge, args.length, args2.length);
        ArrayList c =  new ArrayList(Arrays.asList(strMerge));
        return c;
    }

    public static ArrayList merge2(String[] args,String[] args2){
        //系统自带
        ArrayList mergeArr = new ArrayList(Arrays.asList(args));
        mergeArr.addAll(Arrays.asList(args2));
        return mergeArr;
    }

    private static ArrayList merge2(ArrayList arr1, ArrayList arr2) {
        ArrayList mergeArr = new ArrayList(arr1);
        mergeArr.addAll(arr2);
        return mergeArr;
    }



}
